package com.briup.smartcity.web.controller;

import com.briup.smartcity.aop.Logging;
import com.briup.smartcity.bean.BaseUser;
import com.briup.smartcity.service.IBaseUserService;
import com.briup.smartcity.utils.Result;
import com.briup.smartcity.utils.ResultUtil;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

@Api(tags = "用户方式")
@RestController
@RequestMapping("/auth/user")
public class BaseUserController {
    @Autowired
    private IBaseUserService service;
    @Logging()
    @GetMapping("/info")
    public Result findUserInfoByToken(@ApiIgnore @RequestHeader("Authorization") String token){
        BaseUser user = service.currentUserInfo(token);
        return ResultUtil.success(user);
    }

    /*  @GetMapping("/getLoginUserInfo/{userId}")
      public Result getLoginUserInfo(@PathVariable Integer userId){
          //
          return ResultUtil.success();
      }*/
    //通过id删除用户信息
    @ApiOperation("通过id删除用户信息")
    @DeleteMapping("/delete")
    public Result deleteById(Integer id){
        service.deleteUserById(id);
        return ResultUtil.success();
    }

    //更新头像
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id",value = "Id"),
    })
    @ApiOperation("通过id修改用户头像")
    @PutMapping("/updateUserIcon")
    public Result updateIconById(Integer id,String userIcon){
        System.out.println(id + " " + userIcon);
        service.updateUserIcon(id,userIcon);
        return ResultUtil.success();
    }

    @ApiOperation("通过id修改用户状态")
    @PutMapping("/update/status")
    public Result updateUserById(Integer id,Integer statu){
       // service.updateUserStatus(id,statu);
        return ResultUtil.success();
    }
    @ApiOperation("模糊查找")
    @GetMapping("/page/query")
    public Result getInfoByUsernameAndRole(Integer pageNum,Integer pageSize,String username,Integer role,@ApiIgnore @RequestHeader("Authorization")String token){
        PageInfo<BaseUser> pageInfo2= service.pageQuery2(pageNum, pageSize, username,role,token);
        return ResultUtil.success(pageInfo2);
    }

    @ApiOperation("更新用户信息")
    @PutMapping("/update")
    public Result updateUserInfo(BaseUser user,@ApiIgnore @RequestHeader("Authorization") String token){
        service.updateUser(user,token);
        return ResultUtil.success(user);
    }

    @ApiOperation("获取当前登录用户信息")
    @GetMapping("/info ")
    public Result getLoginingUserInfor(@ApiIgnore @RequestHeader("Authorization") String token){
        BaseUser user = service.currentUserInfo(token);
        return ResultUtil.success(user);
    }

}
